{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73dcdeb8-816c-4185-8630-a51b3df25765",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_csv('./bike_sharing_dc.csv', parse_dates=['date'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6465d86d-69e0-4767-8e89-3a2eec8b4e92",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pygwalker as pyg\n",
    "vis_spec = r\"\"\"{\"config\":[{\"config\":{\"defaultAggregated\":true,\"geoms\":[\"bar\"],\"coordSystem\":\"generic\",\"limit\":-1,\"timezoneDisplayOffset\":0},\"encodings\":{\"dimensions\":[{\"dragId\":\"gw_d0SN\",\"fid\":\"date\",\"name\":\"date\",\"basename\":\"date\",\"semanticType\":\"temporal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_fCVU\",\"fid\":\"month\",\"name\":\"month\",\"basename\":\"month\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_xAWV\",\"fid\":\"season\",\"name\":\"season\",\"basename\":\"season\",\"semanticType\":\"nominal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_ho7q\",\"fid\":\"year\",\"name\":\"year\",\"basename\":\"year\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_1bIC\",\"fid\":\"holiday\",\"name\":\"holiday\",\"basename\":\"holiday\",\"semanticType\":\"nominal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_K8Ek\",\"fid\":\"work yes or not\",\"name\":\"work yes or not\",\"basename\":\"work yes or not\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_tORa\",\"fid\":\"am or pm\",\"name\":\"am or pm\",\"basename\":\"am or pm\",\"semanticType\":\"nominal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_RMSm\",\"fid\":\"Day of the week\",\"name\":\"Day of the week\",\"basename\":\"Day of the week\",\"semanticType\":\"quantitative\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_mea_key_fid\",\"fid\":\"gw_mea_key_fid\",\"name\":\"Measure names\",\"analyticType\":\"dimension\",\"semanticType\":\"nominal\",\"offset\":0},{\"fid\":\"gw_hYau\",\"dragId\":\"gw_hYau\",\"name\":\"Weekday [date]\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"aggName\":\"sum\",\"computed\":true,\"expression\":{\"op\":\"dateTimeFeature\",\"as\":\"gw_hYau\",\"params\":[{\"type\":\"field\",\"value\":\"date\"},{\"type\":\"value\",\"value\":\"weekday\"},{\"type\":\"format\",\"value\":\"%Y-%m-%d\"}]},\"offset\":0},{\"fid\":\"gw_lSdd\",\"dragId\":\"gw_lSdd\",\"name\":\"Quarter [date]\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"aggName\":\"sum\",\"computed\":true,\"expression\":{\"op\":\"dateTimeFeature\",\"as\":\"gw_lSdd\",\"params\":[{\"type\":\"field\",\"value\":\"date\"},{\"type\":\"value\",\"value\":\"quarter\"},{\"type\":\"format\",\"value\":\"%Y-%m-%d\"}]},\"offset\":0}],\"measures\":[{\"dragId\":\"gw_oE-g\",\"fid\":\"hour\",\"name\":\"hour\",\"basename\":\"hour\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_LZNz\",\"fid\":\"temperature\",\"name\":\"temperature\",\"basename\":\"temperature\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_JbdF\",\"fid\":\"feeling_temp\",\"name\":\"feeling_temp\",\"basename\":\"feeling_temp\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_7hAr\",\"fid\":\"humidity\",\"name\":\"humidity\",\"basename\":\"humidity\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_a8mK\",\"fid\":\"winspeed\",\"name\":\"winspeed\",\"basename\":\"winspeed\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_Yb-_\",\"fid\":\"casual\",\"name\":\"casual\",\"basename\":\"casual\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_fdQ9\",\"fid\":\"registered\",\"name\":\"registered\",\"basename\":\"registered\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_Bdj1\",\"fid\":\"count\",\"name\":\"count\",\"basename\":\"count\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_count_fid\",\"fid\":\"gw_count_fid\",\"name\":\"Row count\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"computed\":true,\"expression\":{\"op\":\"one\",\"params\":[],\"as\":\"gw_count_fid\"},\"offset\":0},{\"dragId\":\"gw_mea_val_fid\",\"fid\":\"gw_mea_val_fid\",\"name\":\"Measure values\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0}],\"rows\":[{\"dragId\":\"gw_XI5j\",\"fid\":\"registered\",\"name\":\"registered\",\"basename\":\"registered\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0}],\"columns\":[{\"fid\":\"gw_hYau\",\"dragId\":\"gw_Jx83\",\"name\":\"Weekday [date]\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"aggName\":\"sum\",\"computed\":true,\"expression\":{\"op\":\"dateTimeFeature\",\"as\":\"gw_hYau\",\"params\":[{\"type\":\"field\",\"value\":\"date\"},{\"type\":\"value\",\"value\":\"weekday\"},{\"type\":\"format\",\"value\":\"%Y-%m-%d\"}]},\"offset\":0}],\"color\":[{\"fid\":\"gw_lSdd\",\"dragId\":\"gw_BZBe\",\"name\":\"Quarter [date]\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"aggName\":\"sum\",\"computed\":true,\"expression\":{\"op\":\"dateTimeFeature\",\"as\":\"gw_lSdd\",\"params\":[{\"type\":\"field\",\"value\":\"date\"},{\"type\":\"value\",\"value\":\"quarter\"},{\"type\":\"format\",\"value\":\"%Y-%m-%d\"}]},\"offset\":0}],\"opacity\":[],\"size\":[],\"shape\":[],\"radius\":[],\"theta\":[],\"longitude\":[],\"latitude\":[],\"geoId\":[],\"details\":[],\"filters\":[{\"dragId\":\"gw_U38p\",\"fid\":\"month\",\"name\":\"month\",\"basename\":\"month\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"rule\":{\"type\":\"range\",\"value\":[1,12]},\"offset\":0}],\"text\":[]},\"layout\":{\"showActions\":false,\"showTableSummary\":false,\"stack\":\"stack\",\"interactiveScale\":false,\"zeroScale\":true,\"size\":{\"mode\":\"fixed\",\"width\":350,\"height\":345},\"format\":{},\"geoKey\":\"name\",\"resolve\":{\"x\":false,\"y\":false,\"color\":false,\"opacity\":false,\"shape\":false,\"size\":false},\"colorPalette\":\"paired\",\"scale\":{\"opacity\":{},\"size\":{}},\"scaleIncludeUnmatchedChoropleth\":false,\"useSvg\":false},\"visId\":\"gw_YvK3\",\"name\":\"Chart 1\"},{\"config\":{\"defaultAggregated\":true,\"geoms\":[\"auto\"],\"coordSystem\":\"generic\",\"limit\":-1,\"folds\":[\"registered\",\"casual\"],\"timezoneDisplayOffset\":0},\"encodings\":{\"dimensions\":[{\"dragId\":\"gw_iwKS\",\"fid\":\"date\",\"name\":\"date\",\"basename\":\"date\",\"semanticType\":\"temporal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_qttg\",\"fid\":\"month\",\"name\":\"month\",\"basename\":\"month\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_FJZI\",\"fid\":\"season\",\"name\":\"season\",\"basename\":\"season\",\"semanticType\":\"nominal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_noqw\",\"fid\":\"year\",\"name\":\"year\",\"basename\":\"year\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_S1Op\",\"fid\":\"holiday\",\"name\":\"holiday\",\"basename\":\"holiday\",\"semanticType\":\"nominal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_FECQ\",\"fid\":\"work yes or not\",\"name\":\"work yes or not\",\"basename\":\"work yes or not\",\"semanticType\":\"ordinal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_F4AV\",\"fid\":\"am or pm\",\"name\":\"am or pm\",\"basename\":\"am or pm\",\"semanticType\":\"nominal\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_Srun\",\"fid\":\"Day of the week\",\"name\":\"Day of the week\",\"basename\":\"Day of the week\",\"semanticType\":\"quantitative\",\"analyticType\":\"dimension\",\"offset\":0},{\"dragId\":\"gw_mea_key_fid\",\"fid\":\"gw_mea_key_fid\",\"name\":\"Measure names\",\"analyticType\":\"dimension\",\"semanticType\":\"nominal\",\"offset\":0}],\"measures\":[{\"dragId\":\"gw_KeT-\",\"fid\":\"hour\",\"name\":\"hour\",\"basename\":\"hour\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_rDyp\",\"fid\":\"temperature\",\"name\":\"temperature\",\"basename\":\"temperature\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_G71D\",\"fid\":\"feeling_temp\",\"name\":\"feeling_temp\",\"basename\":\"feeling_temp\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_Gjrm\",\"fid\":\"humidity\",\"name\":\"humidity\",\"basename\":\"humidity\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_2SZj\",\"fid\":\"winspeed\",\"name\":\"winspeed\",\"basename\":\"winspeed\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_Pjzq\",\"fid\":\"casual\",\"name\":\"casual\",\"basename\":\"casual\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_dBk7\",\"fid\":\"registered\",\"name\":\"registered\",\"basename\":\"registered\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_Bju8\",\"fid\":\"count\",\"name\":\"count\",\"basename\":\"count\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0},{\"dragId\":\"gw_count_fid\",\"fid\":\"gw_count_fid\",\"name\":\"Row count\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"computed\":true,\"expression\":{\"op\":\"one\",\"params\":[],\"as\":\"gw_count_fid\"},\"offset\":0},{\"dragId\":\"gw_mea_val_fid\",\"fid\":\"gw_mea_val_fid\",\"name\":\"Measure values\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0}],\"rows\":[{\"dragId\":\"gw_PW8u\",\"fid\":\"gw_mea_val_fid\",\"name\":\"Measure values\",\"analyticType\":\"measure\",\"semanticType\":\"quantitative\",\"aggName\":\"sum\",\"offset\":0}],\"columns\":[{\"dragId\":\"gw_8tGb\",\"fid\":\"date\",\"name\":\"date\",\"basename\":\"date\",\"semanticType\":\"temporal\",\"analyticType\":\"dimension\",\"offset\":0}],\"color\":[{\"dragId\":\"gw_NK9S\",\"fid\":\"gw_mea_key_fid\",\"name\":\"Measure names\",\"analyticType\":\"dimension\",\"semanticType\":\"nominal\",\"offset\":0}],\"opacity\":[],\"size\":[],\"shape\":[],\"radius\":[],\"theta\":[],\"longitude\":[],\"latitude\":[],\"geoId\":[],\"details\":[],\"filters\":[{\"dragId\":\"gw_RBu-\",\"fid\":\"date\",\"name\":\"date\",\"basename\":\"date\",\"semanticType\":\"temporal\",\"analyticType\":\"dimension\",\"rule\":{\"type\":\"temporal range\",\"value\":[1293811200000,1356883200000],\"format\":\"%Y-%m-%d\",\"offset\":-480},\"offset\":0}],\"text\":[]},\"layout\":{\"showActions\":false,\"showTableSummary\":false,\"stack\":\"stack\",\"interactiveScale\":false,\"zeroScale\":true,\"size\":{\"mode\":\"fixed\",\"width\":752,\"height\":360},\"format\":{},\"geoKey\":\"name\",\"resolve\":{\"x\":false,\"y\":false,\"color\":false,\"opacity\":false,\"shape\":false,\"size\":false},\"scaleIncludeUnmatchedChoropleth\":false},\"visId\":\"gw_QwuS\",\"name\":\"Chart 2\"}],\"chart_map\":{},\"workflow_list\":[{\"workflow\":[{\"type\":\"filter\",\"filters\":[{\"fid\":\"month\",\"rule\":{\"type\":\"range\",\"value\":[1,12]}}]},{\"type\":\"transform\",\"transform\":[{\"key\":\"gw_hYau\",\"expression\":{\"op\":\"dateTimeFeature\",\"as\":\"gw_hYau\",\"params\":[{\"type\":\"field\",\"value\":\"date\"},{\"type\":\"value\",\"value\":\"weekday\"},{\"type\":\"format\",\"value\":\"%Y-%m-%d\"},{\"type\":\"displayOffset\",\"value\":0}]}},{\"key\":\"gw_lSdd\",\"expression\":{\"op\":\"dateTimeFeature\",\"as\":\"gw_lSdd\",\"params\":[{\"type\":\"field\",\"value\":\"date\"},{\"type\":\"value\",\"value\":\"quarter\"},{\"type\":\"format\",\"value\":\"%Y-%m-%d\"},{\"type\":\"displayOffset\",\"value\":0}]}}]},{\"type\":\"view\",\"query\":[{\"op\":\"aggregate\",\"groupBy\":[\"gw_hYau\",\"gw_lSdd\"],\"measures\":[{\"field\":\"registered\",\"agg\":\"sum\",\"asFieldKey\":\"registered_sum\"}]}]}]},{\"workflow\":[{\"type\":\"filter\",\"filters\":[{\"fid\":\"date\",\"rule\":{\"type\":\"temporal range\",\"value\":[1293811200000,1356883200000],\"offset\":-480,\"format\":\"%Y-%m-%d\"}}]},{\"type\":\"view\",\"query\":[{\"op\":\"aggregate\",\"groupBy\":[\"date\"],\"measures\":[{\"field\":\"registered\",\"agg\":\"sum\",\"asFieldKey\":\"registered_sum\"},{\"field\":\"casual\",\"agg\":\"sum\",\"asFieldKey\":\"casual_sum\"}]}]}]}],\"version\":\"0.4.9a0\"}\"\"\"\n",
    "walker = pyg.walk(df, spec=vis_spec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80c52eec",
   "metadata": {},
   "outputs": [],
   "source": [
    "walker.display_chart(\"Chart 1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2078f08",
   "metadata": {},
   "outputs": [],
   "source": [
    "walker.display_preview_on_jupyter()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "PyGWalker",
   "language": "python",
   "name": "pygwalker"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
